package com.fesine.quartz.chapter9;

import com.fesine.quartz.chapter4.PrintJob;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.quartz.CronTrigger;
import org.quartz.JobDataMap;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.impl.StdSchedulerFactory;

import java.util.Date;

/**
 * @description: 类描述
 * @author: Fesine
 * @createTime:2016/11/20 16:01
 * @update:修改内容
 * @author: Fesine
 * @updateTime:2016/11/20 16:01
 */
public class RMITestClient {
    public void run() throws Exception {
        Log logger = LogFactory.getLog(RMITestClient.class);
        //同样获取自定义配置文件
        System.setProperty("org.quartz.properties",
                "client.properties");
        //获取scheduler实例
        Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler();
        //定义jobDetail
        JobDetail jobDetail = new JobDetail("remotelyAddedJob", "default", PrintJob
                .class);
        JobDataMap dataMap = new JobDataMap();
        dataMap.put("msg", "Your remotely added job has executed!");
        jobDetail.setJobDataMap(dataMap);
        CronTrigger trigger =
                new CronTrigger("remotelyAddedTrigger",
                        "default", "remotelyAddedJob", "default", new
                        Date(), null, "/5 * * ? * *");

        scheduler.scheduleJob(jobDetail, trigger);
        logger.info("Remote Job scheduled.");
    }

    public static void main(String[] args) throws Exception {
        new RMITestClient().run();
    }
}
